package com.zhangji.springcloud.controller;

import com.zhangji.springcloud.pojo.Dept;
import com.zhangji.springcloud.service.DeptClientServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * @Description: 消费者不应该有service层，调用RestTemplate即可。首先将RestTemplate注册到spring中（详见ConfigBean.java），随后调用方法get/post xxx（url，参数实体：map，响应类型）
 * @Author: Zhang Ji
 * @Date: 2021/6/23 14:16
 * Created by IntelliJ IDEA.
 */
@RestController
public class FeignDeptConsumerController {

    @Autowired
    private DeptClientServer deptClientServer = null;

    /**
     * @Description: 远程调用provider-dept-8001/DeptController/queryDeptById方法
     * @param dept
     * @return dept
     */
    @RequestMapping("/dept/add")
    public boolean addDept(Dept dept){
        return this.deptClientServer.addDept(dept);
    }

    /**
     * @Description: 远程调用provider-dept-8001/DeptController/queryDeptById方法
     * @param id
     * @return dept
     */
    @RequestMapping("/dept/get/{id}")
    public Dept getById(@PathVariable("id") Long id){
        return this.deptClientServer.queryById(id);
    }

    /**
     * @Description: 远程调用provider-dept-8001/DeptController/queryAll方法
     * @return List<Dept>
     */
    @RequestMapping("/dept/getall")
    public List<Dept> getAll(){
        return this.deptClientServer.queryAll();
    }

}
